package com.ymatou.iapi.productmanager.testcase;
import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.productmanager.service.GetUserPreSaleCountCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.database.annotation.SqlMapperFactory;
import com.ymttest.database.annotation.product.IntergratedProductMapper;

public class Ts_GetUserPreSaleCount {
	private static IntergratedProductMapper intergratedProductMapper = SqlMapperFactory.getIntergratedProductMapper();
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取给买手已经发布的预订商品数");
		intergratedProductMapper.updateProductoffSale(3383);
	}
	
	@Before
	public void caseUp() {
	}
	
	@AfterClass
	public static void tearDown() {
		Logger.generateResult(new GetUserPreSaleCountCall().getOpurl());
	}
	
	@After
	public void caseDown() {
		Logger.end(); 
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserPreSaleCount_001() throws Exception {
		Logger.start(true,"获取给买手已经发布的预订商品数");
		try{
			int sqlCount = (Integer)intergratedProductMapper.selectUserPreSaleCount(3383).get("total");
			JSONObject ret = new GetUserPreSaleCountCall().call(3383);
			Logger.verifyEquals(200, ret.getInt("Code"), "返回码检查");
			Logger.verifyEquals(sqlCount, ret.getJSONObject("Data").getInt("Count"), "预售商品个数");
			Logger.verifyEquals(true, ret.getJSONObject("Data").getJSONArray("CatalogStatus").length()>0, "CatalogStatus个数应大于0");
		}catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetUserPreSaleCount_002() throws Exception {
		Logger.start(true,"不存在userId");
		try{
			int sqlCount = (Integer)intergratedProductMapper.selectUserPreSaleCount(1234599).get("total");
			JSONObject ret = new GetUserPreSaleCountCall().call(1234599);
			Logger.verifyEquals(200, ret.getInt("Code"), "返回码检查");
			Logger.verifyEquals(sqlCount, ret.getJSONObject("Data").getInt("Count"), "预售商品个数");
			Logger.verifyEquals(sqlCount, 0, "预售商品个数");
			Logger.verifyEquals(true, ret.getJSONObject("Data").getJSONArray("CatalogStatus").length()>0, "CatalogStatus个数应大于0");
		}catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	
}
